//Creating and Deleting Folders

const fs = require('fs');

//1.make a directory
fs.mkdir('Folder Name',(err)=>{
    if(err) console.log(err);//It would occur if the file already exits.
    else console.log('Folder successfully created');
});

//2.delete a folder
fs.rmdir('Folder Name',(err)=>{
    if(err) console.log(err);
    else console.log('Successfully deleted the folder.');
});

//3.create a folder and a file within the folder
fs.mkdir('Folder Name',(err)=>{
    if(err) console.log(err);//It would occur if the file already exits.
    else{
        fs.writeFile('./Folder Name/File Name.txt','File Content',(err)=>{
            if(err) console.log(err);
            else console.log('Successfully created the folder and file ')
        });
    };
});

//4.delete a folder that has a file within it
fs.unlink('./Folder Name/File Name.txt',(err)=>{
    if(err) console.log(err);
    else{
        fs.rmdir('Folder Name',(err)=>{
            if(err) console.log(err);
            else console.log('Successfully deleted the folder.');
        });
    }
});

//5.delete multiple files within a folder  
fs.readdir('Folder Name',(err,files)=>{//5.1 Read all the files within a target folder and return a list of files.
    if(err) console.log(err);
    else{
        async.series(
            []);
        console.log(files);
        for(let file of files){//5.2 Loot through the array and delete everyting.
            fs.unlink('./Folder Name/'+file,(err)=>{
                if(err) console.log(err);
                else{
                    console.log('Successfully deleted the file '+ file);
                    length++;
                }
            });
        };
    }
});